<template>
  <el-button type="primary" :loading="loading" @click="exportPDF">{{$t('shipment.打印箱标')}}</el-button>
</template>

<script>
import {printShipmentBoxPDF} from "@/api/shipment";

export default {
  name: 'ExportBox',
  props:{
    id:{
      type: Number,
      required: true,
    },
  },
  data(){
    return {
      loading: false,
    }
  },
  methods: {
    exportPDF(){
      this.loading = true
      printShipmentBoxPDF(this.id)
        .then(res=>{
          this.loading = false
          const pdfFile = window.URL.createObjectURL(
            new Blob([res.data], { type: "application/pdf" })
          );

          // 跳转页面预览
          window.open(pdfFile);
          // 60秒后释放
          setTimeout(()=>{
            URL.revokeObjectURL(pdfFile); //释放URL对象
          },60000)
        })
    }
  },
}
</script>

<style scoped lang="scss">

</style>
